package com.gx.gxreader.activity

import android.widget.RadioGroup
import com.gx.gxreader.R
import com.gx.gxreader.base.BaseActivity
import com.gx.gxreader.fragment.*
import com.gx.gxreader.presenter.MainPresenter
import com.gx.gxreader.view.MainView
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : BaseActivity<MainView, MainPresenter>(), MainView, RadioGroup.OnCheckedChangeListener {

    private val bookshelfFragment = BookshelfFragment()
    private val selectedFragment = SelectedFragment()
    private val bubblingFragment = BubblingFragment()
    private val stackRoomFragment = StackRoomFragment()
    private val mineFragment = MineFragment()

    override fun getContentViewId(): Int = R.layout.activity_main

    override fun createPresenter(): MainPresenter = MainPresenter()

    override fun initViews() {
        rgMain.setOnCheckedChangeListener(this)

        addFragment(bookshelfFragment, R.id.flMain)
    }

    override fun onCheckedChanged(p0: RadioGroup?, p1: Int) {
        when (p1) {
        //书架
            R.id.rbBookshelf -> replaceFragment(bookshelfFragment, R.id.flMain)
        //精选
            R.id.rbSelected -> replaceFragment(selectedFragment, R.id.flMain)
        //冒泡
            R.id.rbBubbling -> replaceFragment(bubblingFragment, R.id.flMain)
        //书库
            R.id.rbStackRoom -> replaceFragment(stackRoomFragment, R.id.flMain)
        //我的
            R.id.rbMine -> replaceFragment(mineFragment, R.id.flMain)
        }
    }
}